import java.sql.Connection;
import java.sql.DriverManager;

import com.saic.parse.IImport;
import com.saic.parse.IImportAmong;
import com.saic.parse.impl.ImportBrand;
import com.saic.parse.impl.ImportBrandParseAutoHome;
import com.saic.parse.impl.ImportBrandParseBitauto;
import com.saic.parse.impl.ImportBrandParseXcar;
import com.saic.parse.impl.ImportModel;
import com.saic.parse.impl.ImportModelParseAutoHome;
import com.saic.parse.impl.ImportModelParseBitauto;
import com.saic.parse.impl.ImportModelParseXcar;
import com.saic.parse.impl.ImportSeries;
import com.saic.parse.impl.ImportSeriesParseAutoHome;
import com.saic.parse.impl.ImportSeriesParseBitauto;
import com.saic.parse.impl.ImportSeriesParseXcar;
import com.saic.parse.impl.ImportSeriesRelation;
import com.saic.parse.impl.ImportSubBrand;
import com.saic.parse.impl.ImportSubBrandParseAutoHome;
import com.saic.parse.impl.ImportSubBrandParseBitauto;
import com.saic.parse.impl.ImportSubBrandParseXcar;


public class FaceImport implements IImport,IImportAmong {
	
	//brand
	IImport importBrandAutohome = new ImportBrandParseAutoHome();
	IImport importBrandXcar = new ImportBrandParseXcar();
	IImport importBrandBitauto = new ImportBrandParseBitauto();
	
	//subbrand
	IImport importSubBrandAutohome = new ImportSubBrandParseAutoHome();
	IImport importSubBrandXcar = new ImportSubBrandParseXcar();
	IImport importSubBrandBitauto = new ImportSubBrandParseBitauto();
	
	//series
	IImport importSeriesAutoHome = new ImportSeriesParseAutoHome();
	IImport importSeriesBitauto = new ImportSeriesParseBitauto();
	IImport importSeriesXcar = new ImportSeriesParseXcar();
	IImport importSeriesRelation = new ImportSeriesRelation();

	//model
	IImport importModelAutoHome =new ImportModelParseAutoHome();
	IImport importModelXcar =new ImportModelParseXcar();
	IImport importModelBitauto =new ImportModelParseBitauto();
	
	//result
	IImport importBrand = new ImportBrand();
	IImport importSubBrand = new ImportSubBrand();
	IImport importSeries = new ImportSeries();
	IImportAmong importModel = new ImportModel();

	



	public static void main(String[] args) throws Exception{
		
		String dataParseSql = "jdbc:mysql://192.168.22.70:3306/"+DB_NAME+"?"
	      + "user=dataparse&password=1234&useUnicode=true&characterEncoding=UTF8";
		Class.forName("com.mysql.jdbc.Driver");
		
		Connection connDataParse = DriverManager.getConnection(dataParseSql);


		
		String bartackSql = "jdbc:mysql://192.168.22.70:3306/bartack?"
		      + "user=dataparse&password=1234&useUnicode=true&characterEncoding=UTF8";
			Class.forName("com.mysql.jdbc.Driver");

		Connection connBartack = DriverManager.getConnection(bartackSql);
		
		connBartack.setAutoCommit(false);	
		connDataParse.setAutoCommit(false);
		try{
			FaceImport face = new FaceImport();
			face.importExcel(connBartack,connDataParse);
			face.importExcel(connDataParse);

		}catch (Exception e) {
			connBartack.rollback();
			connDataParse.rollback();
			e.printStackTrace();

		}
		connBartack.commit();
		connDataParse.commit();
	}
	@Override
	public void importExcel(Connection connDataParse) throws Exception {
		// brand
		importBrandAutohome.importExcel(connDataParse);
		importBrandXcar.importExcel(connDataParse);
		importBrandBitauto.importExcel(connDataParse);
		
		// subbrand
		importSubBrandAutohome.importExcel(connDataParse);
		importSubBrandXcar.importExcel(connDataParse);
		importSubBrandBitauto.importExcel(connDataParse);
		
		// series
		importSeriesAutoHome.importExcel(connDataParse);
		importSeriesXcar.importExcel(connDataParse);
		importSeriesBitauto.importExcel(connDataParse);
		importSeriesRelation.importExcel(connDataParse);
		
		//model
		importModelAutoHome.importExcel(connDataParse);
		importModelBitauto.importExcel(connDataParse);
		importModelXcar.importExcel(connDataParse);
		
		connDataParse.createStatement().execute("call face");

	}
	@Override
	public void importExcel(Connection connBartack, Connection connDataParsedb)throws Exception {
		importBrand.importExcel(connBartack);
		importSubBrand.importExcel(connBartack);
		importSeries.importExcel(connBartack);
		importModel.importExcel(connBartack, connDataParsedb);
	}
}
